package com.tarena.lbs.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@Api(tags = "基础服务")
public class TestController {

    @GetMapping("/hello")
    @ApiOperation("基础服务测试")
    public String hello() {
        return "Hello, Knife4j!";
    }

    /**
     * 带参数的测试接口
     * @param name 传入的名称参数
     * @return 包含名称的问候语
     */
    @GetMapping("/greet")
    @ApiOperation("带参数的基础服务测试")
    public String greet(
            @ApiParam(value = "用户名称", required = true, example = "John")
            @RequestParam String name
    ) {
        return "Hello, " + name + "!";
    }

    /**
     * 处理请求体的测试接口
     * @param message 传入的消息对象
     * @return 包含消息内容的响应
     */
    @PostMapping("/message")
    @ApiOperation("处理请求体的基础服务测试")
    public String handleMessage(
            @ApiParam(value = "消息对象", required = true)
            @RequestBody Message message
    ) {
        return "Received message: " + message.getContent();
    }

    // 定义消息类
    static class Message {
        private String content;

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }
}